home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / chslist.h < prev    next >
C/C++ Source or Header  |  1999-03-14  |  5KB  |  149 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- //
  5. // C++ Header File Name: chslist.h 
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer
  8. // File Creation Date: 12/29/1996
  9. // Date Last Modified: 03/15/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ---------- Include File Description and Details  ---------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. A character string singly linked list class derived from the
  32. SNodeBase class and the SLListBase class.
  33. */
  34. // ----------------------------------------------------------- //   
  35. #ifndef __CHSLIST_HPP
  36. #define __CHSLIST_HPP
  37.  
  38. #include "sllistb.h"
  39.  
  40. // General definition of the concrete data type used
  41. typedef char * SLTYPE;
  42.  
  43. // (C)haracter (B)ased (S)ingly Linked List (N)ode class 
  44. class ChSNode: public SNodeBase
  45. {
  46. public:
  47.   ChSNode() { } // Implicitly call default constructor for Data
  48.   ChSNode(const SLTYPE &X) : Data(X) { } // Call copy constructor
  49.  
  50. public:
  51.   ChSNode *GetNext() { return (ChSNode *)Next; }
  52.   const ChSNode *GetNext() const { return (ChSNode *)Next; }
  53.  
  54. public:
  55.   SLTYPE Data;
  56. };
  57.  
  58. // (C)haracter (B)ased (S)ingly (L)inked (L)ist class 
  59. class ChSList : public SLListBase
  60. {
  61. public:
  62.   ChSList() { }
  63.   virtual ~ChSList();
  64.   ChSList(const ChSList &X) { Copy(X); }
  65.   void operator=(const ChSList &X) { Copy(X); }
  66.  
  67. public:
  68.   int Copy(const ChSList &List);
  69.   int Cat(const ChSList &X) { return SLListBase::Cat(X); }
  70.   const ChSNode *Find(const SLTYPE &X, const ChSNode *ptr=0) const;
  71.   ChSNode *Find(const SLTYPE &X, ChSNode *ptr=0);
  72.   int DeleteNext(ChSNode *Node, SLTYPE *X = 0);
  73.   int DeleteFront(SLTYPE *X = 0);
  74.   ChSNode *Store(const SLTYPE &X);
  75.   ChSNode *AddToFront(const SLTYPE &X);
  76.   ChSNode *AddToBack(const SLTYPE &X);
  77.   ChSNode *AddAfter(const SLTYPE &X, ChSNode *Node);
  78.   ChSNode *GetHeader() { return(ChSNode *) this; }
  79.   const ChSNode *GetHeader() const { return(ChSNode *) this; }
  80.   ChSNode *GetFront() { return(ChSNode *)SLListBase::GetFront(); }
  81.   ChSNode *GetBack() { return (ChSNode *)SLListBase::GetBack(); }
  82.   
  83.   const ChSNode *GetFront() const { // Read only version
  84.     return(ChSNode *)SLListBase::GetFront();
  85.   }
  86.  
  87.   const ChSNode *GetBack() const { // Read only version
  88.     return (ChSNode *)SLListBase::GetBack();
  89.   }
  90.  
  91.   int IsHeader(const ChSNode *Node) const {
  92.     return SLListBase::IsHeader(Node);
  93.   }
  94.   SLTYPE *GetFrontNode() {
  95.     ChSNode *ptr = (ChSNode *)SLListBase::GetFront();
  96.     return IsHeader(ptr) ? 0 : &(ptr->Data);
  97.   }
  98.  
  99.   const SLTYPE *GetFrontNode() const {
  100.     ChSNode *ptr = (ChSNode *)SLListBase::GetFront();
  101.     return IsHeader(ptr) ? 0 : &(ptr->Data);
  102.   }
  103.  
  104.   SLTYPE *GetBackNode() {
  105.     ChSNode *ptr = (ChSNode *)SLListBase::GetBack();
  106.     return IsHeader(ptr) ? 0 : &(ptr->Data);
  107.   }
  108.  
  109.   const SLTYPE *GetBackNode() const {
  110.     ChSNode *ptr = (ChSNode *)SLListBase::GetBack();
  111.     return IsHeader(ptr) ? 0 : &(ptr->Data);
  112.   }
  113.  
  114. public:
  115.   void InsertAfter(ChSNode *A, ChSNode *B) {
  116.     SLListBase::InsertAfter(A, B);
  117.   }
  118.  
  119.   void AttachToFront(ChSNode *Node) {
  120.     SLListBase::AttachToFront(Node);
  121.   }
  122.  
  123.   void AttachToBack(ChSNode *Node) {
  124.     SLListBase::AttachToBack(Node);
  125.   }
  126.  
  127.   ChSNode *RmvFront() {
  128.     return(ChSNode *)(SLListBase::RmvFront());
  129.   }
  130.  
  131.   ChSNode *RmvNext(ChSNode *Node) {
  132.     return(ChSNode *)(SLListBase::RmvNext(Node));
  133.   }
  134.  
  135. protected:
  136.   virtual ChSNode *AllocNode(const SLTYPE &X);
  137.   virtual SNodeBase *DupNode(const SNodeBase *Node);
  138.   virtual void FreeNode(SNodeBase *Node);
  139.  
  140. public: // Overloaded operators
  141.   int operator+=(const ChSList &X) { return Cat(X); }
  142. };
  143.  
  144. #endif  // __CHSLIST_HPP 
  145. // ----------------------------------------------------------- //
  146. // ------------------------------- //
  147. // --------- End of File --------- //
  148. // ------------------------------- //
  149.